package agh.io.js {
	import agh.io.api.MapAdapter;
	import agh.io.xmlCommunicator.Communicator;
	import flash.external.ExternalInterface;

	/**
	 * @author endq
	 */
	public class JsController {
		
		protected var adapter : MapAdapter;
		protected var communicator : Communicator;
		
		public function JsController(a:MapAdapter, comm:Communicator) {
			
			adapter = a; 
			communicator = comm;
			
			var clearFunction : Function = clear;
			ExternalInterface.addCallback("clear", clearFunction);	
			
			var editFunction : Function = edit;
			ExternalInterface.addCallback("edit", editFunction);
			
			var cancelEditFunction : Function = cancelEdit;
			ExternalInterface.addCallback("cancelEdit", cancelEditFunction);	
			
			var searchFunction : Function = search;
			ExternalInterface.addCallback("search", searchFunction);	
					
			var showEventLocatationFunction : Function = showEventLocatation;
			ExternalInterface.addCallback("showEventLocatation", showEventLocatationFunction);
						
			var insertEventFunction : Function = insertEvent;
			ExternalInterface.addCallback("insertEvent", insertEventFunction);
						
			var insertOnlyEventFunction : Function = insertOnlyEvent;
			ExternalInterface.addCallback("insertOnlyEvent", insertOnlyEventFunction);			
		}
		
		public function edit():void {
			adapter.edit();
		}		
		
		public function cancelEdit():void {
			adapter.cancelEdit();
		}	
		
		public function clear():void {
			adapter.clear();
		}	
		
		public function search(text:String, valueMin:String, valueMax:String):void {
			communicator.Search(text, valueMin, valueMax);
		}
			
		public function showEventLocatation(locationId:String):void {
			adapter.showEventLocatation(locationId);
		}	
		
		public function insertEvent(eventLocationName:String, eventLocationAdres:String, eventLocationCity:String, eventLocationLocationName:String, eventLocationDescription:String, locationX:String, locationY:String, eventName:String, eventDescription:String, eventValue:String, user:String, tags:String, categores:String):void {
			communicator.InsertEvent(eventLocationName, eventLocationAdres, eventLocationCity, eventLocationLocationName, eventLocationDescription, locationX, locationY, eventName, eventDescription, eventValue, user, tags, categores);
		}	
		
		public function insertOnlyEvent(eventLocationId:String, eventName:String, eventDescription:String, eventValue:String, user:String, tags:String, categores:String):void {		
			communicator.InsertOnlyEvent(eventLocationId, eventName, eventDescription, eventValue, user, tags, categores);
		}
	}
}
